import { nextAnimateFrame, track } from "xbsj-base"
import { CircularInsertEditing } from "../base"
import { ESCesiumViewer } from "@czmSrc/ESCesiumViewer"
import { ESJEditingMode, ESSceneObject } from "earthsdk3"
import { BaseEditingWrapper } from "./BaseEditingWrapper";
export class CircularInsertEditingWrapper extends BaseEditingWrapper {
    static readonly type = this.registerEditing("ESCesiumViewer", ESJEditingMode.CircularInsert, this);
    constructor(sceneObject: ESSceneObject, czmViewer: ESCesiumViewer) {
        super(sceneObject, czmViewer, true);
        const circularInsertEditing = this.currentEditing = this.ad(new CircularInsertEditing(czmViewer));
        this.ad(circularInsertEditing.enabledChanged.don((newVal) => {
            !newVal && this.ad(nextAnimateFrame(() => {
                this.destroy();
            }));
        }));
        do {
            if (Reflect.has(sceneObject, 'points')) {
                //@ts-ignore
                const update = () => circularInsertEditing.positions = sceneObject.points ?? [];
                update();
                //@ts-ignore
                this.ad(sceneObject.pointsChanged.don(() => !circularInsertEditing.enabled && update()));
                circularInsertEditing.enabled = true;
                //@ts-ignore
                this.ad(track([sceneObject, 'points'], [circularInsertEditing, 'positions']));
                break;
            }
            this.supportEditing = false;
        } while (false);
    }
}